#Jaroslav Crhonek (crhonjar@fit.cvut.cz)

def sameword(file)
  #puts "Calling sameword with parameter: #{file}"
  lines = []
  File.open(file,"r") do |f|
    #puts "Reading lines:"
    lines = f.readlines
    #puts "Loaded file:"
    #puts lines

    lines.each_with_index()  do |line,line_no|
      #puts "Analyzing line: #{line}"
      analyzeLine(line,line_no)
    end
  end
end

def analyzeLine(line,line_no)
  words = line.split(" ")
  set = []
  found_duplicities = []
  words.each do |word|
    word = word.downcase
    if set.include?(word)
      if !found_duplicities.include?(word)
        puts "Duplicity on line #{line_no} word: #{word}"
        found_duplicities << word
      end
    else
      set << word
    end
  end
end

puts ">> Start"
sameword("cviko2_2.txt");
puts "<< Stop"